﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="upfile.aspx.cs" Inherits="Catering.UserTraining.upfile" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>上传文档</title>
    <link href="css/css_upfile.css" rel="stylesheet" type="text/css" />
    <link href="js/uploadify-v2.1.4/uploadify.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="js/js_common.js" type="text/javascript"></script>    
    <script src="js/uploadify-v2.1.4/swfobject.js" type="text/javascript"></script>
    <script src="js/uploadify-v2.1.4/jquery.uploadify.v2.1.4.min.js" type="text/javascript"></script>
    <script src="js/js_arraylist.js" type="text/javascript"></script>
</head>
<script type="text/javascript">
    var sKeys = new ArrayList();
    function SubmitUpdate() {
        var result = "[" + TrimEnd($("#SuccessFiles").val(), ',') + "]";
        var returnstr = "";
        if (result != "" && sKeys.size() > 0 && parent.document.getElementById('<%=s_ResultControl_Show %>')) {
            var s = eval("(" + result + ")");
            $.each(s, function (index, item) {
                if (sKeys.getIndex(item.QueueId) > -1) {
                    returnstr += "<dl refid=\"UpFile" + index + "\" filesize='" + item.FileSize + "'><dd>" + decodeURI(item.FileName) + "</dd><dt onclick='DelUPFile(\"UpFile" + index + "\")'></dt><input type=\"hidden\" name=\"UpFile" + index + "\" id=\"UpFile" + index + "\" value=\"" + item.Address + "\" /></dl>";
                }
            });
            parent.document.getElementById('<%=s_ResultControl_Show %>').innerHTML = returnstr;
        }
        parent.$_M.Close();
    }

    function UpSuccessFileJs(name, url,fileSize, queueId) {
        sKeys.add(queueId);
        var ostr = $("#SuccessFiles").val();
        ostr += "{\"FileName\":\"" + encodeURI(TrimEnd(name, ',')) + "\",\"Address\":\"" + TrimEnd(url, ',') + "\",\"FileSize\":\"" + TrimEnd(fileSize, ',') + "\",\"QueueId\":\"" + queueId + "\"},";
        $("#SuccessFiles").val(ostr);
    }
    function DelSuccessFileJs(queueId) {
        sKeys.removeValue(queueId);
    }
</script>
<body>
    <form id="form1" runat="server">
    <div class="up_outer">
        <table width="100%">
            <tr>
                <td><input type="file" name="uploadify" style="display: none" id="uploadify" /></td>
                <td>
                    <%--<a href="javascript:$('#uploadify').uploadifyUpload()">开始上传</a> | --%>
                    <%--<a href="javascript:$('#uploadify').uploadifyClearQueue()">取消上传</a>--%>
                    <input type="hidden" name="SuccessFiles" id="SuccessFiles" /><input type="button" class="btn_new" value="开始上传" onclick="SubmitUpdate()" />
                </td>
            </tr>
        </table>
        <div id="fileQueue"></div>
        <script type="text/javascript">
            $(document).ready(function () {
                $("#uploadify").uploadify({
                    'uploader': 'js/uploadify-v2.1.4/uploadify.swf',
                    'script': 'UpFile.aspx', //后台处理程序的相对路径
                    'scriptData': { 'action': "ok",'UpPath': "<%=s_UpPath %>",'MaxSize': "<%=i_MaxSize %>",'FileNamePrefix': "<%=s_FileNamePrefix %>",'ResultControl_Show': "<%=s_ResultControl_Show %>",'AttachSave': "<%=i_AttachSave %>" },
                    'cancelImg': 'js/uploadify-v2.1.4/cancel.png',
                    'queueID': 'fileQueue',
                    'fileDataName': "file1",

                    'buttonText': '',
                    'buttonImg':'images/uploadify-v2.1.4/bg_liulan.png',
                    'multi': false, //true：上传多个文件，false：只能上传一个文件
                    'auto': true, //设置为true当选择文件后就直接上传了，为false需要点击上传按钮才上传 
                    'fileDesc': '*', //这个属性值必须设置fileExt属性后才有效，
                    'fileExt': '<%=s_FileTye %>', //设置可以选择的文件的类型，格式如：'*.doc;*.pdf;*.rar'
                    'sizeLimit': <%=i_MaxSize %>, //上传文件的大小限制 。单位字节，104857600=100mb
                    'queueSizeLimit': 1, //选择上传文件个数     
                    'removeCompleted': false,
                    'onError': function (event, ID, fileObj, errorObj) {
                    },
                    'onComplete': function (event, queueId, fileObj, response, data) {
                        var result = eval('(' + response + ')');                        
                        if (result.ErrorStr != "") {
                            $("#uploadify").uploadifyCommentError(queueId, { 'type': 'Upload', 'info': result.ErrorStr });
                        }
                        else{
                            UpSuccessFileJs(result.SuccessStr,result.FileName,result.FileSize,queueId);
                        }
                    },
                    'onCancel':function(event, queueId, fileObj, data){
                        DelSuccessFileJs(queueId);
                    },
                    'onClearQueue':function(event,data){
                        sKeys.clear();
                    },
                    'onUploadStart': function (file) {
                    },
                    'onAllComplete': function (event, data) {
                    }
                });
            });
        </script>
        <div></div>
    </div>
    </form>
</body>
</html>

